package NC83_子数组最大乘积;


public class Solution {
    private double Max(double a, double b, double c){
        return Math.max(c, Math.max(b, a));
    }
    private double Min(double a, double b, double c){
        return Math.min(c, Math.min(b, a));
    }
    public double maxProduct(double[] arr) {
        if (arr == null || arr.length == 0){
            return 0;
        }
        int len = arr.length;
        double[] max = new double[len];
        double[] min = new double[len];
        double res = arr[0];
        max[0] = arr[0];
        min[0] = arr[0];
        for (int i = 1; i < len; i++){
            max[i] = Max(arr[i], arr[i] * max[i - 1], arr[i] * min[i - 1]);
            min[i] = Min(arr[i], arr[i] * max[i - 1], arr[i] * min[i - 1]);
            res = Math.max(res, max[i]);

        }
        return res;

    }
}